'''
sorted(iterable,key=None,reverse=False)
reverse : False-->升序默认   True-->降序
将原来的可迭代对象排序，返回排序后的列表，不改变原来的可迭代对象
'''

L = [3,5,2,9,5,74,-1,4,-3]
# 升序
print("升序：",sorted(L))

print("降序：",sorted(L,reverse=True))

print("绝对值升序排序：",sorted(L,key=abs))

# 会改变源列表
L.reverse()
print("反序",L)


L2 = ["tom","jerry","lucy","jack","rose"]
print("升序：",sorted(L2))

print("降序：",sorted(L2,reverse=True))

print("按长度升序：",sorted(L2,key=len))

L2.reverse()
print("反序：",L2)

L3 = []
for n in L2:
    L3.append(''.join(reversed(n)))
    # L3.append(n[::-1])
print("名字倒过来升序：",sorted(L3))